
class OverpressureInterpolate{
    constructor(){
        this.error = [];
        this.H = []; // height of burst。单位：feet
        this.R = []; // 距爆心地面投影点的距离，单位：feet
        this.PSI = [1, 2, 4, 6, 8, 10, 15, 20, 30, 50, 100, 200, 300, 1000, 2000, 5000, 10000];
        this.R[1] = new Array(3854.17, 3888.84, 3944.25, 3990.41, 4095.06, 4199.75, 4305.21, 4409.88, 4514.57, 4620.02, 4724.70, 4830.13, 4935.63, 5040.26, 5144.94, 5250.37, 5355.06, 5459.70, 5565.19, 5669.82, 5774.50, 5879.89, 5984.53, 6089.92, 6195.29, 6299.89, 6405.23, 6405.04, 6509.85, 6615.01, 6720.23, 6824.58, 6929.53, 6962.40, 6996.68, 7016.88, 7016.49, 6994.97, 6929.77, 6825.21, 6720.05, 6614.96, 6509.95, 6404.95, 6299.96, 6194.95, 6090.01, 5985.06, 5880.09, 5774.36, 5670.14, 5565.14, 5460.02, 5354.76, 5250.25, 5144.81, 5040.05, 4935.22, 4830.30, 4724.59, 4620.37, 4514.62, 4409.71, 4304.77, 4199.87, 4094.94, 3990.07, 3885.19, 3780.32, 3780.12, 3675.49, 3569.88, 3465.05, 3360.26, 3255.50, 3150.03, 3044.55, 2939.92, 2834.49, 2729.84, 2625.25, 2519.92, 2415.34, 2310.05, 2205.58, 2100.31, 1995.08, 1889.88, 1784.69, 1679.53, 1575.17, 1470.04, 1364.95, 1259.88, 1154.79, 1049.75, 945.51, 840.45, 777.89, 680.66, 694.50, 652.84, 604.22, 541.67, 368.06, 215.28, 0.00)
        this.H[1] = new Array(0.00, 6.77, 27.77, 47.99, 89.21, 124.18, 160.70, 198.79, 234.54, 272.63, 309.16, 349.59, 380.65, 424.99, 461.52, 501.95, 538.48, 580.48, 612.32, 657.44, 693.97, 739.87, 783.43, 829.34, 878.36, 927.40, 979.55, 1007.68, 1025.45, 1105.74, 1175.86, 1260.06, 1369.25, 1414.51, 1477.74, 1569.12, 1625.38, 1723.87, 1780.25, 1836.71, 1868.16, 1890.24, 1900.59, 1909.38, 1916.61, 1927.75, 1927.94, 1929.70, 1933.03, 1937.13, 1943.58, 1953.15, 1979.92, 2025.43, 2074.85, 2147.72, 2232.30, 2328.61, 2436.64, 2547.79, 2666.75, 2783.38, 2890.62, 3001.77, 3107.45, 3217.04, 3318.82, 3421.37, 3523.15, 3551.28, 3618.67, 3715.76, 3810.50, 3899.78, 3985.14, 4061.92, 4140.25, 4206.86, 4278.17, 4347.90, 4408.27, 4464.72, 4525.08, 4574.51, 4619.24, 4667.10, 4707.93, 4746.42, 4781.78, 4814.01, 4841.55, 4869.10, 4891.96, 4910.91, 4932.98, 4946.46, 4958.38, 4974.98, 4984.48, 4984.66, 4991.67, 4991.74, 4991.83, 4998.98, 4999.31, 4999.60, 5000.00)
        this.R[2] = new Array(2520.17, 2625.53, 2730.13, 2834.71, 2940.03, 3045.33, 3149.87, 3255.15, 3359.67, 3464.96, 3569.41, 3675.43, 3779.89, 3885.06, 3990.26, 4095.31, 4152.79, 4173.24, 4179.69, 4144.29, 4095.23, 3990.51, 3885.27, 3359.71, 3780.19, 3464.60, 3569.49, 3675.19, 3254.67, 3150.25, 3044.95, 2940.12, 2835.27, 2730.39, 2625.55, 2519.90, 2415.04, 2309.42, 2204.61, 2099.81, 1995.03, 1890.31, 1784.87, 1680.17, 1574.79, 1470.20, 1365.63, 1260.37, 1155.10, 1049.89, 944.81, 839.59, 735.22, 630.13, 525.04, 419.96, 314.90, 209.86, 105.62, 0.63)
        this.H[2] = new Array(0.00, 34.14, 83.18, 135.33, 191.39, 250.58, 307.42, 369.74, 429.71, 489.67, 559.80, 627.58, 696.15, 773.31, 846.56, 941.69, 997.84, 1054.06, 1124.37, 1222.89, 1286.27, 1366.95, 1410.12, 1424.39, 1430.64, 1431.23, 1438.06, 1438.65, 1438.65, 1474.79, 1527.34, 1622.87, 1721.52, 1823.29, 1921.16, 2023.72, 2123.15, 2221.80, 2313.42, 2405.03, 2492.74, 2573.42, 2644.72, 2721.49, 2785.76, 2846.91, 2904.92, 2951.22, 2999.08, 3037.57, 3058.86, 3099.69, 3128.02, 3150.87, 3172.17, 3191.90, 3210.07, 3224.33, 3234.68, 3241.91)
        this.R[4] = new Array(1645.85, 1679.66, 1784.71, 1889.76, 1994.76, 2099.77, 2205.55, 2310.46, 2415.23, 2519.97, 2555.89, 2576.33, 2596.73, 2589.39, 1994.88, 2099.80, 2568.12, 2205.33, 1889.72, 2520.04, 2310.09, 2414.95, 1785.26, 1679.88, 1575.20, 1470.31, 1364.90, 1260.19, 1155.49, 1050.06, 944.68, 840.12, 734.88, 629.68, 525.26, 420.12, 315.06, 210.01, 104.96, 13.08)
        this.H[4] = new Array(0.00, 17.95, 113.08, 207.43, 309.59, 410.97, 512.35, 627.80, 762.00, 902.45, 951.61, 1007.83, 1071.08, 1127.35, 1181.60, 1184.53, 1190.68, 1210.90, 1213.05, 1225.94, 1236.49, 1247.23, 1255.44, 1318.93, 1393.36, 1498.26, 1565.65, 1643.21, 1720.76, 1791.28, 1854.77, 1911.22, 1955.18, 1992.88, 2029.02, 2058.13, 2075.51, 2091.34, 2107.95, 2116.71)
        this.R[6] = new Array(1312.52, 1365.35, 1470.11, 1574.91, 1679.68, 1784.52, 1890.06, 1932.01, 1966.29, 1994.89, 1979.10, 1470.44, 1575.33, 1950.98, 1365.28, 1680.09, 1889.76, 1784.77, 1259.95, 1154.50, 1049.77, 945.08, 839.63, 735.04, 629.83, 525.33, 420.17, 315.05, 209.98, 104.94, 30.04)
        this.H[6] = new Array(0.00, 56.82, 192.59, 324.44, 459.42, 584.25, 720.79, 791.03, 854.26, 958.13, 1008.95, 1034.12, 1040.96, 1058.23, 1066.36, 1067.33, 1097.41, 1103.86, 1122.81, 1196.46, 1277.92, 1352.35, 1425.99, 1487.92, 1526.40, 1574.26, 1606.49, 1632.48, 1652.21, 1666.47, 1673.64)
        this.R[8] = new Array(1104.18, 1155.36, 1259.72, 1365.05, 1469.75, 1530.20, 1575.29, 1640.34, 1679.87, 1260.45, 1155.44, 1646.16, 1365.19, 1574.85, 1050.16, 1469.89, 945.52, 840.09, 734.74, 629.41, 524.87, 419.66, 314.50, 210.19, 105.14, 0.08)
        this.H[8] = new Array(0.00, 72.06, 267.21, 433.45, 577.80, 651.14, 713.56, 791.58, 875.89, 939.97, 950.33, 953.31, 967.90, 999.55, 999.75, 1002.87, 1067.14, 1137.67, 1198.03, 1254.48, 1307.03, 1346.30, 1378.53, 1399.04, 1414.87, 1433.04)
        this.R[10] = new Array(1027.50, 1069.31, 1103.35, 1154.93, 1260.08, 1364.72, 1404.56, 1365.22, 1050.29, 1155.13, 945.22, 1259.97, 839.94, 734.49, 629.88, 524.55, 420.06, 314.86, 209.76, 105.42, 0.42)
        this.H[10] = new Array(0.00, 19.09, 117.48, 246.31, 437.55, 592.06, 742.80, 852.26, 870.04, 883.91, 888.21, 897.78, 937.63, 1011.28, 1074.77, 1131.22, 1177.52, 1216.01, 1238.86, 1264.06, 1272.85)
        this.R[15] = new Array(819.00, 791.38, 840.01, 945.15, 1049.82, 1114.21, 1155.20, 1119.84, 840.34, 1050.12, 734.53, 945.16, 629.37, 524.84, 419.46, 314.97, 209.79, 104.68, 0.42)
        this.H[15] = new Array(0.00, 40.71, 150.01, 342.81, 492.64, 553.47, 651.84, 743.33, 768.86, 782.53, 783.12, 785.85, 814.57, 867.12, 931.39, 977.69, 1012.26, 1037.47, 1050.94)
        this.R[20] = new Array(712.50, 716.98, 723.26, 734.83, 745.92, 758.66, 768.27, 778.05, 790.99, 813.56, 836.17, 858.78, 881.40, 904.01, 920.14, 926.59, 920.04, 914.02, 904.00, 723.15, 700.65, 677.98, 881.31, 655.31, 745.81, 632.80, 768.29, 858.79, 790.95, 836.12, 813.62, 610.28, 587.59, 565.07, 542.38, 519.86, 497.17, 474.65, 451.96, 429.44, 406.92, 384.24, 361.56, 339.04, 316.36, 293.85, 271.17, 248.49, 225.98, 203.31, 180.80, 158.13, 135.62, 113.12, 90.44, 67.94, 45.27, 22.60, 0.10)
        this.H[20] = new Array(0.00, 16.57, 51.04, 114.46, 166.00, 224.40, 265.06, 302.71, 342.20, 402.11, 444.28, 481.26, 513.55, 548.53, 575.30, 608.43, 640.06, 652.11, 664.16, 675.54, 677.71, 678.55, 683.40, 684.07, 684.40, 692.10, 692.77, 693.44, 698.80, 698.80, 699.63, 703.31, 718.37, 733.43, 748.49, 762.72, 777.11, 790.66, 803.88, 815.60, 828.65, 840.36, 850.90, 861.11, 870.48, 879.52, 887.88, 896.08, 902.11, 906.63, 912.65, 916.16, 920.52, 923.19, 926.20, 928.88, 930.72, 932.23, 933.73)
        this.R[30] = new Array(591.00, 592.48, 592.44, 593.90, 593.86, 595.32, 596.77, 598.22, 599.67, 602.62, 607.08, 610.19, 615.96, 621.91, 632.82, 639.76, 642.70, 632.81, 610.11, 587.61, 565.11, 542.44, 519.93, 497.25, 474.57, 452.05, 429.36, 406.84, 384.15, 361.64, 339.12, 316.43, 293.92, 271.24, 248.56, 226.04, 203.36, 180.85, 158.18, 135.51, 113.00, 90.33, 67.82, 45.15, 22.65, 0.00)
        this.H[30] = new Array(0.00, 16.57, 42.17, 66.27, 91.87, 121.99, 152.11, 185.24, 219.88, 251.51, 283.13, 316.27, 358.43, 393.07, 453.31, 490.96, 534.64, 570.11, 590.86, 594.88, 596.05, 598.56, 602.41, 611.11, 621.65, 634.04, 647.59, 661.14, 674.70, 686.75, 699.46, 710.84, 720.72, 731.26, 740.96, 749.67, 758.20, 764.22, 769.58, 774.10, 778.28, 781.29, 784.64, 786.81, 789.16, 790.33)
        this.R[50] = new Array(457.50, 458.99, 458.97, 460.44, 460.41, 461.89, 461.86, 463.34, 464.82, 466.29, 467.76, 469.24, 470.72, 473.68, 474.65, 478.12, 482.59, 487.05, 490.01, 491.47, 494.43, 488.37, 474.66, 451.96, 429.44, 406.75, 384.24, 361.55, 339.03, 316.34, 293.83, 271.31, 248.62, 225.94, 203.43, 180.75, 158.24, 135.56, 112.89, 90.38, 67.71, 45.21, 22.54, 0.00)
        this.H[50] = new Array(0.00, 9.04, 22.59, 40.66, 57.23, 73.80, 90.36, 105.42, 121.99, 138.55, 158.13, 173.19, 189.76, 212.35, 230.42, 253.01, 275.60, 302.71, 323.80, 350.90, 379.52, 421.69, 449.46, 469.21, 484.10, 496.99, 509.04, 522.59, 535.31, 549.03, 560.91, 572.29, 583.50, 593.37, 603.08, 611.45, 619.65, 625.67, 630.35, 634.87, 637.38, 640.06, 641.90, 643.07)
        this.R[100] = new Array(340.50, 341.98, 344.96, 346.43, 346.40, 349.37, 350.83, 350.79, 352.25, 353.72, 353.68, 355.14, 353.60, 352.06, 347.52, 338.99, 316.27, 293.90, 271.21, 248.69, 226.01, 203.33, 180.81, 158.13, 135.62, 112.94, 90.27, 67.76, 45.09, 0.00, 22.58)
        this.H[100] = new Array(0.00, 10.54, 28.61, 49.70, 66.27, 87.35, 111.45, 137.05, 164.16, 188.25, 212.35, 242.47, 268.07, 293.67, 317.77, 339.52, 374.16, 396.75, 412.65, 426.20, 438.25, 448.80, 459.34, 468.37, 477.07, 483.43, 488.79, 493.98, 498.49, 500.67, 500.67)
        this.R[200] = new Array(265.50, 265.48, 266.95, 266.93, 268.40, 269.87, 269.85, 269.83, 269.81, 269.78, 268.24, 266.71, 262.17, 253.14, 242.60, 230.58, 218.55, 203.36, 180.84, 158.15, 135.63, 112.95, 90.44, 67.93, 45.26, 22.59, 0.08)
        this.H[200] = new Array(0.00, 12.05, 30.12, 48.19, 67.77, 84.34, 100.90, 112.95, 129.52, 149.10, 171.69, 192.77, 218.37, 242.47, 263.55, 283.13, 298.19, 313.92, 331.33, 345.55, 356.26, 364.79, 371.99, 378.01, 381.69, 385.54, 388.55)
        this.R[300] = new Array(194.14, 194.84, 195.55, 196.98, 198.41, 199.84, 201.27, 201.97, 203.40, 203.36, 203.31, 202.54, 201.03, 198.80, 195.10, 191.40, 186.98, 176.02, 164.99, 154.05, 143.03, 131.95, 120.94, 110.01, 99.00, 88.00, 77.00, 66.00, 55.00, 44.01, 33.02, 22.03, 11.03, 0.04)
        this.H[300] = new Array(0.00, 11.32, 20.09, 31.06, 42.03, 53.73, 66.16, 77.12, 89.55, 102.71, 119.52, 134.14, 148.76, 161.18, 172.87, 184.56, 194.06, 210.52, 225.45, 236.23, 244.98, 250.97, 258.51, 264.82, 270.16, 275.01, 279.54, 283.02, 285.19, 287.36, 289.13, 289.51, 290.22, 290.45)
        this.R[1000] = new Array(153.85, 153.80, 154.51, 155.21, 155.90, 156.60, 157.30, 158.00, 157.97, 157.94, 156.44, 154.22, 151.25, 147.55, 143.05, 132.00, 120.98, 109.96, 99.02, 88.01, 77.01, 66.01, 55.01, 44.01, 33.01, 22.02, 11.03)
        this.H[1000] = new Array(0.00, 14.17, 24.41, 36.10, 48.53, 59.50, 71.19, 82.16, 92.39, 102.63, 113.59, 123.82, 136.24, 147.20, 157.75, 176.74, 189.39, 199.76, 207.78, 214.91, 219.85, 224.54, 228.74, 231.48, 234.30, 235.83, 236.70)
        this.R[2000] = new Array(118.68, 120.11, 120.80, 121.48, 121.43, 120.64, 119.12, 116.13, 109.99, 99.03, 88.01, 77.00, 65.99, 54.99, 43.99, 32.99, 22.00, 11.00, 0.01)
        this.H[2000] = new Array(0.00, 14.11, 28.00, 45.54, 63.09, 80.63, 101.09, 119.36, 133.40, 150.93, 160.98, 168.68, 174.67, 179.93, 183.88, 186.87, 188.31, 190.08, 191.11)
        this.R[5000] = new Array(87.91, 88.62, 88.60, 89.29, 89.26, 89.23, 89.19, 87.69, 85.46, 81.77, 77.02, 66.07, 54.97, 43.96, 32.96, 21.97, 10.97, 0.00)
        this.H[5000] = new Array(0.00, 8.20, 16.24, 29.40, 39.64, 50.60, 62.30, 74.72, 85.68, 96.64, 107.27, 121.06, 129.65, 136.21, 140.57, 142.75, 144.43, 145.31)
        this.R[10000] = new Array(69.60, 70.28, 70.25, 70.21, 70.17, 69.41, 67.92, 65.05, 60.05, 54.98, 50.01, 44.95, 39.98, 35.00, 29.95, 24.98, 20.01, 0.00, 14.96, 4.95, 10.00)
        this.H[10000] = new Array(0.00, 15.48, 28.64, 41.06, 53.49, 62.99, 72.49, 81.02, 91.48, 98.22, 100.64, 104.78, 107.69, 110.44, 112.30, 113.35, 114.80, 115.90, 116.09, 116.32, 116.33)
    }

    // 爆炸当量为1kt，已知超压值p和爆炸高度h，插值求距离r。h单位：feet, r单位：feet。
    r_from_interpolate_1kt(p, h){
        // h单位：feet, r单位：feet
        if(h == undefined || h == NaN){
            this.error = 'r_from_interpolate_1kt: h = ' + h;
            if(debug) console.log(this.error);
            return false;
        }
        if(p < this.PSI[0] || p > this.PSI[this.PSI.length - 1]){
            this.error = 'r_from_interpolate_1kt: p is out of range 1~10000psi';
            if(debug) console.log(this.error);
            return false;
        }
        let p_index = this.PSI.findIndex(nolessthan, p);
        // console.log('r_from_interpolate_1k, p_index:', p_index);
        if(this.PSI[p_index] == p){
            let h_index = this.H[p].findIndex(nolessthan, h);
            if(h < 0.){
                this.error = 'r_from_interpolate_1kt: h < 0';
                if(debug) console.log(this.error);
                return false;
            }
            if(h > this.H[p][this.H[p].length - 1]){
                this.error = 'r_from_interpolate_1kt: for p = ' + p + 'psi, the  maxmimum of h is ' + this.H[p][this.H[p].length - 1] + 'and h = ' + h;
                if(debug) console.log(this.error);
                return false;
            }
            if(h == 0)
                return this.R[p][0];
            return interpolate(this.H[p][h_index], this.R[p][h_index], this.H[p][h_index - 1], this.R[p][h_index - 1], h); // 如果h == this.H[p][h_index], 则返回值等于this.R[p][h_index]
        }
        // 若p不在this.PSI中，采取的插值方式为双线性插值:在超压值小于p的曲线和超压值大于p的曲线上找到或插值得到爆炸高度为h的两个点(h1, r1), (h2, r2), 然后插值得到r
        else{ 
            let p1 = this.PSI[p_index];
            let p2 = this.PSI[p_index - 1];
            let h_max = interpolate(p1, this.H[p1][this.H[p1].length -1], p2, this.H[p2][this.H[p2].length -1], p);
            // console.log('r_from_interpolate_1k, h_max:', h_max);
            if(0 < h && h <= h_max){
                let h1_index = this.H[p1].findIndex(nolessthan, h);
                let h2_index = this.H[p2].findIndex(nolessthan, h);
                let r1 = interpolate(this.H[p1][h1_index], this.R[p1][h1_index], this.H[p1][h1_index - 1], this.R[p1][h1_index - 1], h);
                let r2 = interpolate(this.H[p2][h2_index], this.R[p2][h2_index], this.H[p2][h2_index - 1], this.R[p2][h2_index - 1], h);
                // console.log('r_from_interpolate_1k, h1_index:', h1_index, 'h2_index', h2_index, 'r1:', r1, 'r2:', r2);
                return interpolate(p1, r1, p2, r2, p);
            }
            else if(h == 0){
                return interpolate(p1, this.R[p1][0], p2, this.R[p2][0], p);
            }
            else if(h > h_max){
                this.error = 'r_from_interpolate_1kt: h is too high to interpolate';
                if(debug) console.log(this.error);
                return false;
            }
        }        
    }

    // 已知超压值p和爆炸高度h，插值求距离r。h单位：feet, r单位：feet。
    r_from_interpolate(W, p, h){
        // console.log('in r_from_interpolate, W:', W, 'p:', p, 'h:', h);
        // h单位：feet, r单位：feet, yield单位：kt。
        let scaled_h = h * Math.pow(1/W, 1/3);
        let r1 = this.r_from_interpolate_1kt(p, scaled_h);
        return r1 * Math.pow(W, 1/3);
    }

    // 通过插值得到使超压p影响范围最大的爆炸高度。返回优化高度h(feet), 最大距离r(feet).
    opt_height_for_psi_from_interpolate(W, p){
        // return h, r. h: feet; r: feet
        if(p < 1 || p > 10000){
            this.error = 'opt_height_for_psi_from_interpolate: p is out of range 1~10000psi, p = ' + p;
            if(debug) console.log(this.error);
            return -1;
        }
        let p_index = this.PSI.findIndex(nolessthan, p);
        let r_max = 0;
        let r_max_index = 0;
        if(this.PSI[p_index] == p){
            for(var i = 0; i < this.R[p].length; i ++){
                if(this.R[p][i] >= r_max){
                    r_max = this.R[p][i];
                    r_max_index = i;
                }
            }
            // console.log('r_max_index, length', r_max_index, this.R[p].length);
            return [this.H[p][r_max_index]*Math.pow(W, 1/3), r_max*Math.pow(W, 1/3)];
        }
        else{
            let p1 = this.PSI[p_index];
            let p2 = this.PSI[p_index - 1];
            let r1_max = 0;
            let r1_max_index = 0;
            let r2_max = 0;
            let r2_max_index = 0;
            for(var i = 0; i < this.R[p1].length; i++){
                if(this.R[p1][i] >= r1_max){
                    r1_max = this.R[p1][i];
                    r1_max_index = i;
                }
            }
            for(var i = 0; i < this.R[p2].length; i++){
                if(this.R[p2][i] >= r2_max){
                    r2_max = this.R[p2][i];
                    r2_max_index = i;
                }
            }
            r_max = interpolate(p1, r1_max, p2, r2_max, p);
            let h_opt = interpolate(p1, this.H[p1][r1_max_index], p2, this.H[p2][r2_max_index], p);
            // console.log('in opt_height_for_psi_from_interpolate, p1, p2, r1_max, r2_max', p1, p2, r1_max, r2_max);
            return [h_opt*Math.pow(W, 1/3), r_max*Math.pow(W, 1/3)];
        }
    }

    // 通过插值得到爆炸当量W(kt), 爆炸高度this.H(feet), 距爆心距离this.R(feet)处超压值p(psi)
    psi_from_interpolate(W, input_h, input_r){
        // input: W: kt; H: feet; this.R: feet;
        // return: p: psi
        let h = input_h * Math.pow(1/W, 1/3);
        let r = input_r * Math.pow(1/W, 1/3);
        // 从外部曲线开始，通过插值的方式得到曲线上的高度为h的点，找到邻近r的两个点后停止
        let r1 = -1; // 大于等于r
        let r2 = -1; // 小于等于r
        let p1; // r1对应超压值
        let p2; // r2对应超压值
        let r_tmp;
        // 地面爆炸， h = 0;
        if(h == 0){
            for(var i = 0; i < this.PSI.length; i ++){
                let r_tmp = this.R[this.PSI[i]][0];
                // 处理特殊情况
                // 为已有数据点
                if(r_tmp == r){
                    return this.PSI[i]
                }
                // 在1psi曲线外部
                if(i == 0 && r > r_tmp){
                    return 0;
                }
                // 在10000psi内部
                if(i == this.PSI.length - 1 && r < r_tmp){
                    return  '大于680atm'
                }
                if(r_tmp >= r){
                    r1 = r_tmp;
                    p1 = this.PSI[i];
                }
                if(r_tmp <= r && r2==-1){
                    r2 = r_tmp;
                    p2 = this.PSI[i];
                }
                if(debug) console.log('psi_interpolation, psi_from_interpolate: r', r, 'r_tmp', r_tmp, 'r1', r1, 'r2', r2);
                if(r1!=-1 && r2!=-1){
                    return interpolate(r1, p1, r2, p2, r);
                }
            }
        }
        // 空中爆炸
        for(var i = 0; i < this.PSI.length; i ++){
            let h_index = this.H[this.PSI[i]].findIndex(nolessthan, h)
            if(h_index == -1){
                continue;
            }
            // 特殊情况，正好是已有的数据点
            if(this.H[this.PSI[i]][h_index] == h && this.R[this.PSI[h_index]][h_index] == r)
                return this.PSI[i];
            r_tmp = interpolate(this.H[this.PSI[i]][h_index], this.R[this.PSI[i]][h_index], this.H[this.PSI[i]][h_index - 1], this.R[this.PSI[i]][h_index - 1], h);
            // 特殊情况，r在1psi曲线外部
            if(i == 0 && r_tmp < r){
                return 0;
            }
            // 特殊情况，r在10000psi曲线内部
            if(i == this.PSI.length - 1 && r < r_tmp){
                return '大于680atm';
            }
            if(r_tmp >= r){
                r1 = r_tmp;
                p1 = this.PSI[i];
            }
            if(r_tmp <= r && r2==-1){
                r2 = r_tmp;
                p2 = this.PSI[i];
            }
            // 大多数情况，在[1psi, 10000psi]内
            if(debug) console.log('psi_interpolation, psi_from_interpolate: r', r, 'r_tmp', r_tmp, 'r1', r1, 'r2', r2);
            if(r1!=-1 && r2!=-1){
                return interpolate(r1, p1, r2, p2, r);
            }
        }
    }
}


if (typeof register == 'function') { register("psi_interpolation.js"); }